package day_2022_9_to_12.Day;

/**
 * @author haomin
 * @date 2022/09/04 11:29
 **/
public class Day2_4_Num6169_LongestNiceSubarray {
    public static void main(String[] args) {
        System.out.println(longestNiceSubarray(new int[]{1,3,8,48,10}));
    }
    public static int longestNiceSubarray(int[] nums) {
        int maxLen = 0;
        int[] dp = new int[nums.length];
        dp[0] = 1;
        for(int i = 1; i < nums.length; ++i){
            if(judge(dp, nums, i-1, i)) {
                dp[i] = dp[i-1]+1;
            }else dp[i] = 1;
            maxLen = Math.max(maxLen, dp[i]);
        }
        return maxLen;
    }

    private static boolean judge(int[] dp, int[] nums, int j, int i) {
        int count = dp[j];
        while(count-- > 0){
            if(!((nums[j] & nums[i]) == 0)) return false;
            j--;
        }
        return true;
    }

}